Skip to content

Unify ATS withEnvironment exports#15649

Open
sebastienros wants to merge 7 commits intomainfrom
sebros/abstract-ats-withenvironment
Open

Unify ATS withEnvironment exports#15649
sebastienros wants to merge 7 commits intomainfrom
sebros/abstract-ats-withenvironment

Conversation

@sebastienros
Copy link
Copy Markdown
Contributor

@sebastienros sebastienros commented Mar 27, 2026

Description

Unifies ATS WithEnvironment exports so polyglot apphosts can use a single withEnvironment(name, value) API, following the same abstraction pattern used for withReference.

On the C# side, this adds the new public IExpressionValue abstraction plus additive WithEnvironment(..., IExpressionValue) support, giving environment values a common base type for cases that need both runtime values and manifest expressions without changing existing constructors or removing existing overloads.

To avoid breaking existing polyglot apps, this PR also keeps the previous ATS withEnvironment* aliases as obsolete internal compatibility shims (withEnvironmentExpression, withEnvironmentEndpoint, withEnvironmentParameter, withEnvironmentConnectionString, withEnvironmentFromOutput, and withEnvironmentFromKeyVaultSecret). Comments in the shim implementations call out that they should be removed once callers have migrated to the unified withEnvironment(...) export.

The generated ATS artifacts plus TypeScript, Java, Python, Go, and Rust snapshots are refreshed to match that final non-breaking export surface.

Documentation follow-up: microsoft/aspire.dev#640

Fixes #3773

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 27, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15649

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15649"

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sebastienros sebastienros marked this pull request as ready for review March 27, 2026 19:16
Copilot AI review requested due to automatic review settings March 27, 2026 19:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR unifies Aspire Type System (ATS) environment-variable exports across polyglot app hosts by consolidating multiple specialized WithEnvironment* capability exports into a single withEnvironment(name, value) capability that accepts a broader set of value types.

Changes:

  • Introduces an internal withEnvironment dispatcher export that accepts a union of supported environment value types (string, expressions, endpoint refs, parameters, connection strings, value providers).
  • Removes specialized ATS exports (and generated polyglot APIs) like withEnvironmentExpression, withEnvironmentEndpoint, withEnvironmentParameter, etc., updating TypeScript/Python codegen snapshots and ATS baselines accordingly.
  • Adds support types/interfaces for dispatching custom environment behavior and exports IValueProvider / IManifestExpressionProvider into ATS.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts Snapshot updates reflecting unified TS withEnvironment union-typed API and removal of specialized methods.
tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/HostingContainerResourceCapabilities.verified.txt Removes specialized environment capability entries from TS capability baseline snapshot.
tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py Snapshot updates reflecting unified Python with_env union typing and removal of specialized methods/options.
src/Aspire.Hosting/api/Aspire.Hosting.Capabilities.txt ATS baseline updated: withEnvironment now takes a union of supported types; specialized exports removed.
src/Aspire.Hosting/ResourceBuilderExtensions.cs Adds internal dispatcher export, value-provider wiring, and reflection-based custom dispatch mechanism.
src/Aspire.Hosting/ApplicationModel/IValueWithCustomWithEnvironment.cs Introduces a new experimental interface for value-specific WithEnvironment dispatch behavior.
src/Aspire.Hosting/ApplicationModel/IValueProvider.cs Exports IValueProvider into ATS.
src/Aspire.Hosting/ApplicationModel/IManifestExpressionProvider.cs Exports IManifestExpressionProvider into ATS.
src/Aspire.Hosting.CodeGeneration.TypeScript/AtsTypeScriptCodeGenerator.cs Updates TS generator to emit proper TS unions for ATS union parameters.
src/Aspire.Hosting.Azure/AzureBicepResourceExtensions.cs Stops exporting Azure-specific withEnvironmentFrom* ATS methods; routes through unified environment API.
src/Aspire.Hosting.Azure/AzureBicepResource.cs Makes BicepOutputReference provide custom WithEnvironment dispatch.
src/Aspire.Hosting.Azure.KeyVault/AzureKeyVaultSecretResource.cs Adds custom WithEnvironment dispatch for Key Vault secret resource values.
src/Aspire.Hosting.Azure.KeyVault/AzureKeyVaultSecretReference.cs Adds custom WithEnvironment dispatch for Key Vault secret references.
src/Aspire.Hosting.SqlServer/api/Aspire.Hosting.SqlServer.ats.txt Refreshes checked-in ATS baseline for SqlServer package to match new shared capability set.
playground/polyglot/TypeScript/Aspire.Hosting/ValidationAppHost/apphost.ts Updates playground usage to call unified withEnvironment for endpoint/parameter/connection-string values.
playground/polyglot/TypeScript/Aspire.Hosting.Azure/ValidationAppHost/apphost.ts Updates playground usage to call unified withEnvironment for Bicep output & Key Vault secret values.
playground/polyglot/Python/Aspire.Hosting/ValidationAppHost/apphost.py Updates playground usage to call unified with_environment for endpoint/parameter/connection-string values.
playground/polyglot/Python/Aspire.Hosting.Azure/ValidationAppHost/apphost.py Updates playground usage to call unified with_environment for Bicep output & Key Vault secret values.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
sebastienros and others added 2 commits March 27, 2026 13:26
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sebastienros sebastienros marked this pull request as draft March 30, 2026 16:00
Keep the new IExpressionValue-based C# abstraction while collapsing ATS back to a single preview-only withEnvironment export. Update generated ATS artifacts and polyglot codegen snapshots to match the unified surface.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sebastienros sebastienros marked this pull request as ready for review March 30, 2026 17:05
@sebastienros sebastienros marked this pull request as draft March 30, 2026 17:10
Keep the unified withEnvironment export while restoring legacy ATS alias methods as obsolete internal compatibility shims for existing polyglot apps. Regenerate capability dumps and refresh codegen snapshots to match the non-breaking export surface.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
/// <param name="name">The name of the environment variable.</param>
/// <param name="value">The reference expression value.</param>
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
[Obsolete("ATS compatibility shim. Use withEnvironment instead. Remove after existing polyglot app hosts migrate.")]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only on an internal method for use to remember to remove this ATS method at some point. We can replace it by a dedicated [AspireExportObsolete] once we have it

@sebastienros sebastienros marked this pull request as ready for review March 30, 2026 17:27
@github-actions
Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 52 recordings uploaded (commit 7e72f6d)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RunWithMissingAwaitShowsHelpfulError ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
TypeScriptAppHostWithProjectReferenceIntegration ▶️ View Recording

📹 Recordings uploaded automatically from CI run #23757986005

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider introducing common base type for "reference" types that implement IManifestExpressionProvider, IValueProvider

2 participants